﻿@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>数据初始化</title>
    <link rel="stylesheet" href="~/Content/bootstrap.min.css" />
    <link rel="stylesheet" href="~/Content/bootstrap-table.css" />
    <link rel="stylesheet" href="~/Content/style.css" />
    <link rel="stylesheet" href="~/Content/alertify.min.css" />
    <link rel="stylesheet" href="~/Content/themes/default.min.css" />
    <style>
        h2 {
            line-height: normal;
            margin-top: 0px;
        }

        #text {
            border-left: 1px solid #ccc !important;
        }

        .div_hidden {
            display: none;
        }
    </style>
</head>
<body>
    @Html.Action("Top", "Home")
    <div class="top_search">
        <form class="form1" style="margin-left:0; border-left:1px solid #ccc;" onsubmit="InitTable(); return false;">
            <input type="text" id="text" placeholder="输入ID、用户名或者姓名">
            <input type="submit" id="btn" class="jb" value="查询">
        </form>
        <div class="tool">
            <a href="#" class="jb" id="add" onclick="onInitUser();">初始化所选操作员所有数据</a>
        </div>
    </div>

    <div class="clear"></div>

    <div class="table1">
        <table></table>
    </div>

    <script src="~/Scripts/jquery-1.10.2.min.js"></script>
    <script src="~/Scripts/bootstrap.min.js"></script>
    <script src="~/Scripts/bootstrap-table.js"></script>
    <script src="~/Scripts/locale/bootstrap-table-zh-CN.js"></script>
    <script src="~/Scripts/uilts.js"></script>
    <script src="~/Scripts/extensions/export/bootstrap-table-export.js"></script>
    <script>
        var $table = $('table');
        function InitTable(pageIndex, pageSize) {
            if (typeof pageIndex == "object") {
                pageIndex = undefined;
            }
            $table.bootstrapTable('destroy');
            $table.bootstrapTable({
                method: "post",  //使用get请求到服务器获取数据
                url: "/User/userlist", //获取数据的Servlet地址
                striped: true,  //表格显示条纹
                pagination: true, //启动分页
                pageSize: pageSize == null ? 10 : pageSize,  //每页显示的记录数
                pageNumber: pageIndex == null ? 1 : pageIndex, //当前第几页
                pageList: [10, 20, 50, 100, 250],  //记录数可选列表
                search: false,  //是否启用查询
                showColumns: true,  //显示下拉框勾选要显示的列
                showRefresh: true,  //显示刷新按钮
                sidePagination: "server", //表示服务端请求
                sortName: "ID",
                //设置为undefined可以获取pageNumber，pageSize，searchText，sortName，sortOrder
                //设置为limit可以获取limit, offset, search, sort, order
                queryParamsType: "undefined",
                queryParams: function queryParams(params) {   //设置查询参数
                    var param = {
                        PageIndex: params.pageNumber,
                        PageSize: params.pageSize,
                        search: $("#text").val().trim(),
                        sorter: params.sortName + " " + params.sortOrder
                    };
                    return param;
                },
                columns: [
                    {
                        field: 'userid',
                        title: "用户ID",
                        align: 'center',
                        valign: 'middle'
                    },
                    {
                        field: 'username',
                        title: '用户名',
                        align: 'center',
                        valign: 'middle'
                    },
                    {
                        field: 'name',
                        title: '姓名',
                        align: 'center',
                        valign: 'middle'
                    },
                    {
                        field: 'level_type',
                        title: '用户级别',
                        align: 'center',
                        valign: 'middle',
                        formatter: function (value, row, index) {
                            if (value == 3) {
                                return '超级管理员';
                            } else if(value == 2) {
                                return '管理员';
                            } else {
                                return '操作员';
                            }
                        }
                    }
                ],
                onLoadSuccess: function () {
                    $('table tr:even').find('td').css("background", "#e9f3ff");
                    $('table tr').click(function () {
                        uncheckAll($table);
                        $('table tr').removeClass("act");
                        $(this).addClass("act");
                        $table.bootstrapTable('check', $(this).attr("data-index"));
                    });
                }
            });
        }

        InitTable();

    </script>
    <script src="~/Scripts/menu.js"></script>
    <script src="~/Scripts/alertify.min.js"></script>
    <script>
        function onInitUser() {
            var selected = $table.bootstrapTable("getSelections");
            if (selected != undefined && selected.length > 0) {
                alertify.confirm("提示", "确定初始化操作员【" + selected[0].name + "】的所有数据？", function () {
                    PostApi("/System/InitData", { user_id: selected[0].id }, function (result) {
                        if (result.code == 0) {
                            InitTable();
                            alertify.success("初始化完成！");
                        } else {
                            alertify.error(result.ErrorMessage);
                        }
                    }, function () {
                        alertify.error("初始化失败！");
                    });
                }, function () { });
            } else {
                alertify.error("未选择需要初始化的操作员！");
            }
        }
    </script>
</body>
</html>
